/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ReenviarDoc.java
 *
 * Created on 25/10/2012, 10:56:47 PM
 */
package Gui;

import ClassControl.CtrReenviar;
import ClassEntidad.DistribucionDoc;
import ClassEntidad.Funcionario;
import ClassEntidad.Persona;
import ClassEntidad.Sistema;
import javax.swing.JOptionPane;
import util.CparaCombo;

/**
 *
 * @author borisgr04
 */
public class ReenviarDoc extends javax.swing.JFrame {

    DistribucionDoc dd;
    Funcionario f;
    CtrReenviar cr;

    /** Creates new form ReenviarDoc */
    public void inicialziarDoc() {
        for (Funcionario d : Sistema.instancia().getOtrosFuncionarios()) {
            this.destinoC.addItem(new CparaCombo(d.getNroIde(), d.getNombres()));
        }
             this.setResizable(false);
        this.setLocationRelativeTo(null);
    }

    public ReenviarDoc() {
        initComponents();
        inicialziarDoc();

    }

    public ReenviarDoc(DistribucionDoc dd) {
        this.dd = dd;
        initComponents();
        this.documentL.setText(dd.getDocumento().getNoDocumento() + "-" + dd.getDocumento().getAsunto());
        inicialziarDoc();
        

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        destinoC = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        obserJT = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        documentL = new javax.swing.JLabel();
        reenviarB = new javax.swing.JButton();
        cancelarB = new javax.swing.JButton();

        setTitle("Reenviar Documento");
        setResizable(false);

        jLabel5.setText("Destino");

        jLabel1.setText("Observaciones");

        obserJT.setColumns(20);
        obserJT.setRows(5);
        jScrollPane1.setViewportView(obserJT);

        jLabel2.setText("Documento N°");

        documentL.setText(" ");

        reenviarB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Email-Forward-icon.png"))); // NOI18N
        reenviarB.setText("Reenviar");
        reenviarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reenviarBActionPerformed(evt);
            }
        });

        cancelarB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Undo-icon.png"))); // NOI18N
        cancelarB.setText("Cerrar");
        cancelarB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap(12, Short.MAX_VALUE))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel5)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                                    .addComponent(destinoC, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel1))
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(documentL, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                            .addGap(97, 97, 97)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(reenviarB)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelarB)
                        .addGap(23, 23, 23))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(10, 10, 10)
                .addComponent(documentL)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(destinoC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(reenviarB)
                    .addComponent(cancelarB))
                .addGap(25, 25, 25))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void reenviarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reenviarBActionPerformed
        // TODO add your handling code here:
        try 
        {
        cr= new CtrReenviar(Sistema.instancia().getEmf());
            CparaCombo depDes = (CparaCombo) destinoC.getSelectedItem();
            if (depDes == null) {
                JOptionPane.showMessageDialog(this, "Seleccione Destinatario", Sistema.instancia().getNomApp(), JOptionPane.WARNING_MESSAGE);
            }
            cr.setDd(dd);
            cr.reenviar(Sistema.instancia().getUsuAct().getNroIde(),depDes.getCodigo() );
            if(cr.isValido())
            {
            JOptionPane.showMessageDialog(this, cr.getMensaje(), Sistema.instancia().getNomApp(), JOptionPane.INFORMATION_MESSAGE);
            this.setVisible(false);
            }
            else {
            JOptionPane.showMessageDialog(this, cr.getMensaje(), Sistema.instancia().getNomApp(), JOptionPane.ERROR_MESSAGE);
            }
        }
        catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex.getMessage(), Sistema.instancia().getNomApp(), JOptionPane.ERROR_MESSAGE);
        
        }
    }//GEN-LAST:event_reenviarBActionPerformed

    private void cancelarBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarBActionPerformed
        // TODO add your handling code here:
        this.setEnabled(false);
    }//GEN-LAST:event_cancelarBActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ReenviarDoc().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelarB;
    private javax.swing.JComboBox destinoC;
    private javax.swing.JLabel documentL;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea obserJT;
    private javax.swing.JButton reenviarB;
    // End of variables declaration//GEN-END:variables
}
